<?php
	header('content-type:text/html;charset=utf-8');
	class SearchAction extends Action {
		public function index(){
			
			R('Public/index');	
			
		}
		/**
		 * 查询和标签搜索
		 *
		 */
		public function search(){
			if ($this->isGet()) {
				$keywords='%'.I('get.keywords').'%';
				$map['keywords']=array('LIKE',$keywords);
				$data=M('Content')->where($map)->select();
				//评论数统计
				$com=M('Comment');
				$sql="select artid ,count('artid') as commentnum from lyolzj_comment group by artid";
				$commentnumber=$com->query($sql);
				$this->assign('commentnumber',$commentnumber);
			}elseif ($this->isPost()){
				$search='%'.I('post.search').'%';
				$map['title']=array('LIKE',$search);
				$data=M('Content')->where($map)->select();
				//评论数统计
				$com=M('Comment');
				$sql="select artid ,count('artid') as commentnum from lyolzj_comment group by artid";
				$commentnumber=$com->query($sql);
				$this->assign('commentnumber',$commentnumber);
			}
			$this->assign('data',$data);
			$this->index();
			$this->display('index');
		}
		
		public function mypage($num){
			/************分页*************/
			import('ORG.Util.Page');
			$m=M('Content');
			$pagewhere['menuid']=$num;
			$count=$m->where($pagewhere)->count();
			$page=new Page($count,5);
			$data = $m->where($pagewhere)->order('ptime')->limit($page->firstRow.','.$page->listRows)->select();
			$this->assign('data',$data);
			//评论数统计
			$com=M('Comment');
			$sql="select artid ,count('artid') as commentnum from lyolzj_comment group by artid";
			$commentnumber=$com->query($sql);
			$this->assign('commentnumber',$commentnumber);
			$show= $page->show();
			$this->assign('pageshow',$show);
		}
		public function internet(){
			$this->index();
			$this->mypage(1);
			$this->display('index');
		}
		public function sport(){
			$this->mypage(2);
			$this->index();
			$this->display('index');
		}
		public function entertainment(){
			$this->mypage(3);
			$this->index();
			$this->display('index');
		}
		public function news(){
			$this->mypage(4);
			$this->index();
			$this->display('index');
		}
	}
?>